<template>
<div>
  <h1 align="center">登录页面</h1>
  <form  align="center">
    用户名:<el-input v-model="username" placeholder="请输入内容" style="width:300px; "></el-input>
    <br>
    密&nbsp;&nbsp;&nbsp;码:<el-input placeholder="请输入密码" v-model="password" show-password  style="width:300px;"></el-input>
    <br>
    <el-button type="primary" plain @click="Login">登录</el-button>
  </form>

</div>
</template>

<script>
export default {
  name: "Login",
  data(){
    return{
      username:'',password:''
    }
  },
  methods:{
  Login(){
    let user = new FormData
    user.append('username',this.username)
    user.append('password',this.password)
    this.$axios.post('login/',user)
    .then(resp=>{
      console.log(resp.data)
      if(resp.data.code==200){
        localStorage.setItem('token',resp.data.token)
        localStorage.setItem('username',resp.data.username)
        this.$router.push('/')
      }
    }).catch(err=>{
      console.log(err)
    })
  }
  }
}
</script>

<style scoped>

</style>
